﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Timetable.aspx.cs" Inherits="Web.Timetable.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">

    <link rel="stylesheet" href="/Share/Styles/Timetable.css" />

    <script type="text/javascript">

        function InitAdditionalControlsForTimetable() {
            $("#TbWeekNo").spinner("option", "min", 1);
            $("#TbWeekNo").spinner("option", "max", 2);
            $("#TbWeekNo").spinner({
                stop: function () {
                    var weekDescr = new Array('Непарная', 'Парная');
                    var weekNo = $("#TbWeekNo").spinner("value");
                    $("#LblWeekDescription").text(weekDescr[weekNo - 1]);
                }
            });

            $("#TbDayNo").spinner("option", "min", 1);
            $("#TbDayNo").spinner("option", "max", 6);
            $("#TbDayNo").spinner({
                stop: function () {
                    var days = new Array('Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс');
                    var dayNo = $("#TbDayNo").spinner("value");
                    $("#LblDayName").text(days[dayNo - 1]);
                }
            });

            $("#TbPairNo").spinner("option", "min", 1);
            $("#TbPairNo").spinner("option", "max", 10);

            SetLabels();
        };

        function SetLabels() {
            var weekDescr = new Array('Непарная', 'Парная');
            var weekNo = $("#TbWeekNo").spinner("value");
            $("#LblWeekDescription").text(weekDescr[weekNo - 1]);

            var days = new Array('Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс');
            var dayNo = $("#TbDayNo").spinner("value");
            $("#LblDayName").text(days[dayNo - 1]);
        };

        function FillEditTimetableUnitForm(week, day, pairNo, groupId, timetableUnitId, subjectId, workType, teacherId, room) {
            $("#TbWeekNo").val(week);
            $("#TbDayNo").val(day);
            $("#TbPairNo").val(pairNo);
            $("#DdlGroups").val(groupId);

            $("#EditTimetableUnitFormError").hide();

            if (timetableUnitId > 0) {
                $("#DdlSubjects").val(subjectId);
                $("#DdlWorkTypes").val(workType);
                $("#DdlTeachers").val(teacherId);
                $("#TbRoom").val(room);

                $("#FieldTimetableUnitId").val(timetableUnitId);
                $("#BtnDeleteTimetableUnit").show();
                ShowEditTimetableUnitForm("Изменить в расписании");
            }
            else {
                $("#DdlSubjects option")[0].selected = true;
                $("#DdlWorkTypes option")[0].selected = true;
                $("#DdlTeachers option")[0].selected = true;
                $("#TbRoom").val('');

                $("#FieldTimetableUnitId").val(0);
                $("#BtnDeleteTimetableUnit").hide();
                ShowEditTimetableUnitForm("Добавить в расписание");
            }
            SetLabels();
            ScrollToEditTimetableUnitForm();
        }

        function HideEditTimetableUnitForm() {
            $("#EditTimetableUnitForm").hide();
        }

        function ScrollToEditTimetableUnitForm() {
            var position = $("#EditTimetableUnitForm").offset();
            scroll(0, position.top);
        }

        function ShowEditTimetableUnitForm(header) {
            $("h4").text(header);
            $("#EditTimetableUnitForm").show();
        }

    </script>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Main" runat="server">
    
    <section id="JournalFiters" class="inset-shadow box clear-fix filter">

        <div class="wrapper left">
            <asp:DropDownList runat="server" ID="DdlSemestersFilter" AutoPostBack="True" OnSelectedIndexChanged="DdlSemestersFilter_OnSelectedIndexChanged" />
        </div>

        <div class="wrapper left">
            <asp:DropDownList runat="server" ID="DdlGroupsFilter" AutoPostBack="True" OnSelectedIndexChanged="DdlGroupsFilter_OnSelectedIndexChanged" />
        </div>

        <div class="wrapper left">
            <asp:DropDownList runat="server" ID="DdlSubjectsFilter" AutoPostBack="True" OnSelectedIndexChanged="DdlSubjectsFilter_OnSelectedIndexChanged" />
        </div>
        
        <div class="wrapper left">
            <asp:DropDownList runat="server" ID="DdlTeachersFilter" AutoPostBack="True" OnSelectedIndexChanged="DdlTeachersFilter_OnSelectedIndexChanged" />
        </div>

    </section>

    <asp:UpdatePanel ID="UpdatePanelTimetable" runat="server">
        <ContentTemplate>
            <section id="TimetableSection" class="inset-shadow box">

                <aside runat="server" id="EditTimetableUnitForm" class="form hidden">
                    <h4>Изменить или добавить в расписание</h4>
                    <input runat="server" id="FieldTimetableUnitId" type="hidden" value="0" />
                    <div runat="server" id="EditTimetableUnitFormError" class="form-error" />
                    <table>
                        <tr>
                            <td>Неделя</td>
                            <td>
                                <asp:TextBox runat="server" ID="TbWeekNo" CssClass="spinner" Text="1" />
                                <asp:Label runat="server" ID="LblWeekDescription" Text="Непарная" />
                            </td>
                        </tr>
                        <tr>
                            <td>День</td>
                            <td>
                                <asp:TextBox runat="server" ID="TbDayNo" CssClass="spinner" Text="1" />
                                <asp:Label runat="server" ID="LblDayName" Text="Пн" />
                            </td>
                        </tr>
                        <tr>
                            <td>Пара</td>
                            <td>
                                <asp:TextBox runat="server" ID="TbPairNo" CssClass="spinner" Text="1" />
                            </td>
                        </tr>
                        <tr>
                            <td>Группа</td>
                            <td>
                                <asp:DropDownList runat="server" ID="DdlGroups" />
                            </td>
                        </tr>
                        <tr>
                            <td>Предмет</td>
                            <td>
                                <asp:DropDownList runat="server" ID="DdlSubjects" />
                            </td>
                        </tr>
                        <tr>
                            <td>Тип занятия</td>
                            <td>
                                <asp:DropDownList runat="server" ID="DdlWorkTypes" />
                            </td>
                        </tr>
                        <tr>
                            <td>Преподаватель</td>
                            <td>
                                <asp:DropDownList runat="server" ID="DdlTeachers" />
                            </td>
                        </tr>
                        <tr>
                            <td>Аудитория</td>
                            <td>
                                <asp:TextBox runat="server" ID="TbRoom" Text="" />
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <asp:Button runat="server" ID="BtnSaveTimetableUnit" CssClass="button" Text="Сохранить" OnClick="BtnSaveTimetableUnit_OnClick" />
                                <asp:Button runat="server" ID="BtnDeleteTimetableUnit" CssClass="button" Text="Удалить" OnClientClick="return confirm('Точно удалить?');" OnClick="BtnDeleteTimetableUnit_OnClick" />
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <a class="button" onclick="HideEditTimetableUnitForm();">Отменить</a>
                            </td>
                        </tr>
                    </table>
                </aside>

                <div runat="server" id="Timetables" EnableViewState="False"></div>

            </section>
        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>
